//
//  TriangleButton.swift
//  SwiftProject
//
//  Created by 董駸 on 2022/8/4.
//

import UIKit

// MARK: - 自定义带三角的按钮 （可自定义三角的方向 大小 颜色）
enum TriangleDirection : Int {
    case up = 0
    case down
    case left
    case right
}

class TriangleButton: QMUIButton {

    private init() {
        super.init(frame: .zero)
    }
    
    private override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    convenience init(triangleSize : CGSize, triangleColor : UIColor, arrowDirection : ArrowDirection = .right) {
        self.init()
        switch arrowDirection {
        case .right:
            setImage(.qmui_image(with: .triangle, size: triangleSize, tintColor: triangleColor)?.qmui_image(with: .right), for: .normal)
        case .left:
            setImage(.qmui_image(with: .triangle, size: triangleSize, tintColor: triangleColor)?.qmui_image(with: .left), for: .normal)
        case .up:
            setImage(.qmui_image(with: .triangle, size: triangleSize, tintColor: triangleColor)?.qmui_image(with: .down), for: .normal)
        case .down:
            setImage(.qmui_image(with: .triangle, size: triangleSize, tintColor: triangleColor), for: .normal)
        }
    }
    
    convenience init(triangleSize : CGSize, triangleColor : UIColor, arrowDirection : ArrowDirection = .right, frame : CGRect) {
        self.init(triangleSize: triangleSize, triangleColor: triangleColor, arrowDirection: arrowDirection)
        self.frame = frame
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
